﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="WaitForBookmark.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace TrackingStateMachine.Activities
{
    using System.Activities;

    /// <summary>
    /// The wait for bookmark.
    /// </summary>
    public sealed class WaitForBookmarkForClass<AuditProcess> : NativeActivity<AuditProcess>
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets BookmarkName.
        /// </summary>
        public InArgument<string> BookmarkName { get; set; }

        #endregion

        #region Properties

        /// <summary>
        /// Gets a value indicating whether CanInduceIdle.
        /// </summary>
        protected override bool CanInduceIdle
        {
            get
            {
                return true;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        protected override void Execute(NativeActivityContext context)
        {
            //context.CreateBookmark(
            //    this.BookmarkName.Get(context), 
            //    (activityContext, bookmark, value) =>
            //    activityContext.ResumeBookmark(new Bookmark(this.BookmarkName.Get(activityContext)), null));
            context.CreateBookmark(BookmarkName.Get(context), new BookmarkCallback(OnResumeBookmark));   //创建书签

        }

        public void OnResumeBookmark(NativeActivityContext context, Bookmark bookmark, object obj)
        {
            // When the Bookmark is resumed, assign its value to
            // the Result argument.
            Result.Set(context, (AuditProcess)obj);
        }

        #endregion
    }
}